<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Goods/goodsadd')}">添加商品</a></li>
    </ul>
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered frrom">
                    <tr>
                        <th width="100">分类<span class="form-required">*</span></th>
                        <td>
                            <select style="width: 30%;height: 2em;" name="" id="cate">
                                <volist name="data" id="vo">
                                <option value="{$vo.id}">{$vo.name}</option>
                                </volist>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>名称<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control name" type="text" name="post[post_title]"
                                   id="title" required value="" placeholder="请输入标题"/>
                        </td>
                    </tr>
                    <tr>
                        <th>价格<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control price" type="number" name="post[post_title]"
                                   id="price" required value="0" placeholder="请输入价格"/>
                        </td>
                    </tr>
                    <tr>
                        <th>销量<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="number" name="post[post_title]"
                                   id="sales" required value="0" placeholder="请输入销量"/>
                        </td>
                    </tr>
                    <tr>
                        <th><b>封面图</b><span class="form-required">*</span></th>
                        <td>
                            <div style="text-align: center;">
                                <input type="hidden" class="thumbb" name="post[more][thumbnail]" id="thumbnail" value="">
                                <a href="javascript:uploadOneImagea('图片上传','#thumbnail');">
                                    <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                         id="thumbnail-preview"
                                         width="135" style="cursor: pointer"/>
                                </a>
                                <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
                            </div>
                        </td>
                    </tr>
                    <script>
                        function uploadOneImagea(dialog_title, input_selector, extra_params, app) {
                            openUploadDialog(dialog_title, function (dialog, files) {
                                $(input_selector).val(files[0].preview_url);
                                $(input_selector + '-preview').attr('src', files[0].preview_url);
                                $(input_selector + '-name').val(files[0].name);
                            }, extra_params, 0, 'image', app);
                        }
                    </script>
                    <tr>
                        <th>详细介绍</th>
                        <td>
                            <script type="text/plain" id="content" name="post[post_content]"></script>
                        </td>
                    </tr>
                    <tr>
                        <th><b>状态</b></th>
                        <td>
                            <div class="checkbox">
                                <label><input class="checkk" type="checkbox" name="post[post_status]" value="1">推荐</label>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th><b>添加时间</b></th>
                        <td>
                            <input class="form-control js-bootstrap-datetime" type="text" name="post[published_time]"
                                   value="{:date('Y-m-d H:i:s',time())}">
                        </td>
                    </tr>
                </table>

                <div class="form-group">
                    <audio class="mpp3" style="display: none;" controls="controls">
                        <source src="__TMPL__/public/6480.mp3"/>
                    </audio>
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" style="width: 10vw;" class="btn btn-success subb">确认提交</button>
                    </div>
                </div>
                <script>
                    $('.subb').click(function () {
                        //获取分类信息
                        var cate = $("#cate  option:selected").val();
                        //获取名称
                        var name = $('.name').val();
                        //获取价格
                        var price = $('#price').val();
                        //获取销量
                        var sales = $('#sales').val();
                        //获取封面图
                        var thumbbb = $('.thumbb').val();
                        //获取详细内容
                        var des = UE.getEditor( 'content' ).getContent();
                        //判断是否选中
                        var check = $('.checkk').is(':checked');
                        //是否为推荐
                        if(check == 1){
                            check = 1;
                        }else {
                            check = 0;
                        }
                        $.ajax({
                            url:'/mainiu/goods/add',
                            type:"post",
                            data:{
                                cate:cate,
                                name:name,
                                price:price,
                                sales:sales,
                                thumb:thumbbb,
                                des:des,
                                ishot:check
                            },
                            success:function(data){
                                var ress= $.parseJSON(data);
                                if(ress.sta==1){
                                    $('.mpp3')[0].play();
                                    alert('提交成功');
                                    location.reload()
                                }else {
                                    alert(ress)
                                }
                            },
                            error:function(e){
                                alert('失败');
                            }
                        });
                    });
                </script>
            </div>
        </div>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });
</script>
</body>
</html>
